import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:xiongan_app_yy/pages/common/LoadBuilder.dart';
import 'package:xiongan_app_yy/provider/out_handover_details_info_provider.dart';
import 'package:xiongan_app_yy/widgets/comm/left_icon_widget.dart';

class OutHandoverDetailsInfo extends StatefulWidget {
  List data;

  OutHandoverDetailsInfo(this.data);

  @override
  _OutHandoverDetailsInfoState createState() => _OutHandoverDetailsInfoState();
}

class _OutHandoverDetailsInfoState extends State<OutHandoverDetailsInfo> {

  @override
  Widget build(BuildContext context) {

    return Scaffold(
      appBar: AppBar(
        leading: LeftIconWidget(icon: Icons.chevron_left, isize: 36),
        backgroundColor: Color(0XFF00A5F1),
        title: Text(
          "物资明细",
          style: TextStyle(fontSize: 18),
        ),
        elevation: 0,
        centerTitle: true,
      ),
      body: LoadBuilder(
        visibility:
            Provider.of<OutHandoverDetailsInfoProvider>(context).netStatus1,
        builder: Column(
          children: <Widget>[
            Expanded(
                child: ListView.builder(
                        itemBuilder: (BuildContext context, int index) {
                          return IntoHandOverDetailsInfoItem(widget.data[index]);
                        },
                        itemCount: widget.data.length),
                    ),
          ],
        ),
      ),
    );
  }
}

class IntoHandOverDetailsInfoItem extends StatelessWidget {
  dynamic data;

  IntoHandOverDetailsInfoItem(this.data);

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      margin: EdgeInsets.only(top: 6),
      padding: EdgeInsets.all(10),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Container(
            width: 120,
            height: 120,
            color: Colors.grey,
            margin: EdgeInsets.only(right: 10),
            child: Image.network('${data['imageurl']}'),
          ),
          Expanded(
              child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Padding(
                padding: EdgeInsets.only(bottom: 4),
                child: _Text("物资编码：${data["materialcode"]}"),
              ),
              Padding(
                padding: EdgeInsets.only(bottom: 4),
                child: _Text("物资名称：${data["materialname"]}"),
              ),
              Padding(
                padding: EdgeInsets.only(bottom: 4),
                child: _Text("型号：${data["model"]}"),
              ),
              Padding(
                padding: EdgeInsets.only(bottom: 4),
                child: _Text("规格：${data["spec"]}"),
              ),
              Padding(
                padding: EdgeInsets.only(bottom: 4),
                child: _Text("基本单位：${data["baseunitname"]}"),
              ),
              Padding(
                padding: EdgeInsets.only(bottom: 4),
                child: _Text("计划数量：${data["quantity"]}"),
              ),
              Padding(
                padding: EdgeInsets.only(bottom: 4),
                child: _Text("实际数量：${data["realquantity"]}"),
              ),
              Padding(
                padding: EdgeInsets.only(bottom: 4),
                child: _Text("差异数量：${data["diffquantity"]}"),
              ),
            ],
          ))
        ],
      ),
    );
  }
}

class _Text extends Text {
  TextStyle style;

  _Text(String data,
      {this.style = const TextStyle(color: Color(0xff646464), fontSize: 14)})
      : super(data, style: style);
}
